from flask import request, session, redirect

from app.common.Constant import Constant


class Interceptor:

    @staticmethod
    def register(app):
        # 注册拦截器方法列表
        # funcs = [Interceptor.checkLogin]
        funcs = []

        @app.before_request
        def before():
            for func in funcs:
                res = func(app)
                if res is not None:
                    return res

    @staticmethod
    def checkLogin(app):
        # 获取session
        username = session.get(Constant.USERNAME)
        if username:
            return

        # 失败校验，或者冲定项登录

        # 重定向
        return redirect(client.login(request))
        # return redirect('http://www.baidu.com')
